package com.woniuxy.service.impl;

import com.woniuxy.entity.SysOrganization;
import com.woniuxy.mapper.SysOrganizationMapper;
import com.woniuxy.service.SysOrganizationService;
import com.woniuxy.util.ResponseEnum;
import com.woniuxy.util.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 组织机构服务实现类
 * 实现组织机构相关的业务逻辑
 */
@Service
public class SysOrganizationServiceImpl implements SysOrganizationService {
    @Resource
    private SysOrganizationMapper sysOrganizationMapper;

    /**
     * 查询所有组织机构
     * @return 查询结果
     */
    @Override
    public ResponseUtil findAllSysOrganization() {
        List<SysOrganization> allSysOrganization = sysOrganizationMapper.findAllSysOrganization();
        return allSysOrganization.size() > 0 ? ResponseUtil.get(ResponseEnum.OK,allSysOrganization)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 根据ID查询组织机构
     * @param id 组织机构ID
     * @return 查询结果
     */
    @Override
    public ResponseUtil findSysOrganizationById(Integer id) {
        SysOrganization sysOrganization = sysOrganizationMapper.findSysOrganizationById(id);
        return sysOrganization != null ? ResponseUtil.get(ResponseEnum.OK,sysOrganization)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 根据名称查询组织机构
     * @param orgName 组织机构名称
     * @return 查询结果
     */
    @Override
    public ResponseUtil findSysOrganization(String orgName) {
        List<SysOrganization> sysOrganization = sysOrganizationMapper.findSysOrganization(orgName);
        return sysOrganization.size() > 0 ? ResponseUtil.get(ResponseEnum.OK,sysOrganization)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 添加组织机构
     * @param sysOrganization 组织机构信息
     * @return 添加结果
     */
    @Override
    public ResponseUtil addSysOrganization(SysOrganization sysOrganization) {
        Integer addSysOrganization = sysOrganizationMapper.addSysOrganization(sysOrganization);
        return addSysOrganization > 0 ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 删除组织机构
     * @param id 组织机构ID
     * @return 删除结果
     */
    @Override
    public ResponseUtil deleteSysOrganization(Integer id) {
        Integer deleteSysOrganization = sysOrganizationMapper.deleteSysOrganization(id);
        return deleteSysOrganization > 0 ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 更新组织机构状态
     * @param id 组织机构ID
     * @param status 状态
     * @return 更新结果
     */
    @Override
    public ResponseUtil updateStatus(Integer id,Integer status) {
        Integer updateStatus = sysOrganizationMapper.updateStatus(id,status);
        return updateStatus > 0 ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}
